﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DatabaseEntegreItri.DataModel
{
    public class PathShortenConverter : System.Windows.Data.IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                FileInfo fi = new FileInfo((string)value);
                if (fi.Directory.ToString().Split('\\').Length > 2)
                {
                    return fi.Directory.Root + "...\\" + fi.Name;
                }
                else
                {
                    return fi.FullName;
                }
            }
            catch { return value; }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
